<?php

class StudentsController extends Zend_Controller_Action
{

	public function init()
	{
		$this -> session = new Zend_Session_Namespace("Students");
	}

	public function indexAction()
	{

	}

	// Students login page
	public function loginAction()
	{
		$id = $this -> _getParam("id");
		$pwd = $this -> _getParam("pwd");

		if (empty($id) || empty($pwd))
		{

			$this -> render();
		}
		else
		{
			$studentsModel = new Application_Model_Students();
			if ($studentsModel -> checkLogin($id, $pwd))
			{
				$this -> session -> id = $id;
				$this -> _redirect("/students/dashboard");
			}
			else
			{
				$this -> view -> error = "Login Failed";
				$this -> render();
			}
		}
	}

	// Students Dashboard
	public function dashboardAction()
	{
		if (empty($this -> session -> id))
		{
			$this -> _redirect("/");
		}
		else
		{
			$studentsModel = new Application_Model_Students();
			$this -> view -> data = $studentsModel -> getUserData($this -> session -> id);
			$noticeBoardModel = new Application_Model_NoticeBoard();
			$this -> view -> notices = $noticeBoardModel -> getNotices($this -> view -> data['batch']);

			$this -> render();
		}
	}

}
